package com.cop4331.social;

import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
import android.widget.TextView;

/**
 * 
 * @author Matt Szoke
 * @LastUpdated: 3/5/2012 by Matt Szoke
 * 
 * Allows the user to choose which tutoring option they're interested in
 * 
 */
public class TutorOptionActivity extends Activity {

	Button need;
	Button want;
	Button cancel;

	// -----------------------------------------------
	// ONCREATE
	// -----------------------------------------------
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.tutoroption);

		// Buttons
		want = (Button) findViewById(R.id.b_want);
		need = (Button) findViewById(R.id.b_need);
		cancel = (Button) findViewById(R.id.b_cancel);

		// Gives functionality to want button
		want.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {

				// Goto CanTutorActivity
				Intent i = new Intent(getApplicationContext(),
						CanTutorActivity.class);
				startActivity(i);
				finish();

			}
		});

		// Gives functionality to need button
		need.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {

				// Goto NeedTutorActivity
				Intent i = new Intent(getApplicationContext(),
						NeedTutorActivity.class);
				startActivity(i);
				finish();

			}
		});

		// Gives functionality to cancel button
		cancel.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {

				// Goto Dashboard
				Intent i = new Intent(getApplicationContext(),
						DashBoardActivity.class);
				startActivity(i);
				finish();

			}
		});

		ImageButton about, home, message;

		about = (ImageButton) findViewById(R.id.b_about);
		home = (ImageButton) findViewById(R.id.b_home);
		message = (ImageButton) findViewById(R.id.b_message);

		UserFunctions uf = new UserFunctions();

		// get current user info from database
		DatabaseHandler db = new DatabaseHandler(getApplicationContext());
		HashMap<String, String> user = db.getUserDetails();
		String un = user.get("name");

		JSONObject j_mess = uf.retreiveMessages(un, "new");

		try {
			if (Integer.parseInt(j_mess.getString("size")) > 0) {
				message.setVisibility(View.VISIBLE);
			} else
				message.setVisibility(View.GONE);
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (JSONException e) {
			e.printStackTrace();
		}

		about.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {

				Dialog dialog = new Dialog(TutorOptionActivity.this);

				dialog.setContentView(R.layout.help_dialog);
				dialog.setTitle("CramSessions v 1.0 2012");
				dialog.setCancelable(true);

				// Create and show a dialog to help the user with this specific
				// field
				TextView text = (TextView) dialog.findViewById(R.id.text);
				text.setText("CramSessions was created by:\n\n-Matt Szoke\n-Daniel Moody\n-Jeovanny Alvarez\n-Kia Manoochehri\n-Rj Anderson\n-Doug Wagner");
				text.setGravity(Gravity.LEFT);
				dialog.setCanceledOnTouchOutside(true);
				dialog.show();
			}
		});

		home.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {

				Intent sa = new Intent(getApplicationContext(),
						DashBoardActivity.class);
				startActivity(sa);
				finish();

			}
		});

		message.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {

				Intent sa = new Intent(getApplicationContext(),
						MessageNotifications.class);
				startActivity(sa);
				finish();

			}
		});
	}
}
